package com.drinks.yiniang.ui.widget.pop;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.listview.CategoryPopAdapter;
import com.drinks.yiniang.entity.category.SubCategoryJson;
import com.hansen.library.listener.CheckDoubleClickListener;
import com.hansen.library.ui.widget.listview.FixedHeightListView;
import com.hansen.library.ui.widget.pop.YNPopupWindow;
import com.hansen.library.utils.CommonUtils;
import com.hansen.library.utils.ScreenSizeUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author han
 * @date 2019/9/20
 */
public class LocationPopup {

    //菜单显示PopupWindow
    private YNPopupWindow mPopupWindow;

    private FrameLayout fl_home_location_parent;
    private TextView tv_home_location_address;

    public void showLocationPop(View anchor, Context context) {
        if (mPopupWindow == null) {
            //设置contentView
            View contentView = LayoutInflater.from(context).inflate(R.layout.pop_home_location, null);
            mPopupWindow = new YNPopupWindow(contentView,
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            mPopupWindow.setContentView(contentView);

            fl_home_location_parent = contentView.findViewById(R.id.fl_home_location_parent);

            tv_home_location_address = contentView.findViewById(R.id.tv_home_location_address);

            fl_home_location_parent.setOnClickListener(new CheckDoubleClickListener() {
                @Override
                public void onCheckDoubleClick(View v) {
                    dismissPop();
                }
            });

            //解决5.0以下版本点击外部不消失问题
            mPopupWindow.setOutsideTouchable(true);
            mPopupWindow.setBackgroundDrawable(new ColorDrawable());
        }

        //显示方式
        mPopupWindow.showAsDropDown(anchor, 0, 2);
    }

    public void setPopupLocationAddress(String address) {
        if(tv_home_location_address != null) {
            tv_home_location_address.setText(address);
        }
    }

    public void dismissPop() {
        if(mPopupWindow != null && mPopupWindow.isShowing()) {
            mPopupWindow.dismiss();
        }
    }
}
